<?php
namespace app\common\model;

use think\Db;
use think\Model;

/**   YSF
 *    动态通知  Model
 *    Date: 2018/7/24
 * Class DynamicModel
 * @package app\common\model
 */
class DynamicModel extends Model
{
    // 表名
    protected $dbName = 'dynamic';

    // 列表查询
    public function getAll($where = [], $nowPage = 1, $limits = 10, $field = '*', $order = 'create_time DESC')
    {
        $result = Db::name($this->dbName)
                    ->where($where)
                    ->field($field)
                    ->page($nowPage,$limits)
                    ->order($order)
                    ->select();
        return $result;
    }

    // 数量查询
    public function getCount($where)
    {
        $result = Db::name($this->dbName)
                    ->where($where)
                    ->count();
        return $result;
    }

    // 添加操作
    public function add($data)
    {
        $result = Db::name($this->dbName)->insertGetId($data);

        return $result;
    }

    // 单条查询
    public function getOne($where)
    {
        $result = Db::name($this->dbName)->where($where)->find();

        return $result;
    }

    // 编辑操作
    public function edit($where, $data)
    {
        $result = Db::name($this->dbName)->where($where)->update($data);

        return $result;
    }

}